{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Requirement already satisfied: pandas in c:\\programdata\\anaconda3\\lib\\site-packages (1.0.1)\n",
      "Requirement already satisfied: pytz>=2017.2 in c:\\programdata\\anaconda3\\lib\\site-packages (from pandas) (2019.3)\n",
      "Requirement already satisfied: numpy>=1.13.3 in c:\\programdata\\anaconda3\\lib\\site-packages (from pandas) (1.18.1)\n",
      "Requirement already satisfied: python-dateutil>=2.6.1 in c:\\programdata\\anaconda3\\lib\\site-packages (from pandas) (2.8.1)\n",
      "Requirement already satisfied: six>=1.5 in c:\\programdata\\anaconda3\\lib\\site-packages (from python-dateutil>=2.6.1->pandas) (1.14.0)\n"
     ]
    }
   ],
   "source": [
    "!pip install pandas\n",
    "import pandas as pd"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"96b989b6f0364a908eb58e1b8c78f008\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_96b989b6f0364a908eb58e1b8c78f008 = echarts.init(\n",
       "                    document.getElementById('96b989b6f0364a908eb58e1b8c78f008'), 'white', {renderer: 'canvas'});\n",
       "                var option_96b989b6f0364a908eb58e1b8c78f008 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"pie\",\n",
       "            \"clockwise\": true,\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"\\u5e7f\\u4e1c\\u7701\",\n",
       "                    \"value\": 67809.85\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6c5f\\u82cf\\u7701\",\n",
       "                    \"value\": 65088.32\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u5c71\\u4e1c\\u7701\",\n",
       "                    \"value\": 59426.59\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6d59\\u6c5f\\u7701\",\n",
       "                    \"value\": 40173.03\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5357\\u7701\",\n",
       "                    \"value\": 34938.24\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6cb3\\u5317\\u7701\",\n",
       "                    \"value\": 29421.15\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u8fbd\\u5b81\\u7701\",\n",
       "                    \"value\": 28626.58\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u56db\\u5ddd\\u7701\",\n",
       "                    \"value\": 28536.66\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5317\\u7701\",\n",
       "                    \"value\": 27379.22\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"\\u6e56\\u5357\\u7701\",\n",
       "                    \"value\": 27037.32\n",
       "                }\n",
       "            ],\n",
       "            \"radius\": [\n",
       "                80,\n",
       "                60\n",
       "            ],\n",
       "            \"center\": [\n",
       "                \"40%\",\n",
       "                \"30%\"\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8,\n",
       "                \"formatter\": \"{b}: {d}%\"\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u5e7f\\u4e1c\\u7701\",\n",
       "                \"\\u6c5f\\u82cf\\u7701\",\n",
       "                \"\\u5c71\\u4e1c\\u7701\",\n",
       "                \"\\u6d59\\u6c5f\\u7701\",\n",
       "                \"\\u6cb3\\u5357\\u7701\",\n",
       "                \"\\u6cb3\\u5317\\u7701\",\n",
       "                \"\\u8fbd\\u5b81\\u7701\",\n",
       "                \"\\u56db\\u5ddd\\u7701\",\n",
       "                \"\\u6e56\\u5317\\u7701\",\n",
       "                \"\\u6e56\\u5357\\u7701\"\n",
       "            ],\n",
       "            \"selected\": {}\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    }\n",
       "};\n",
       "                chart_96b989b6f0364a908eb58e1b8c78f008.setOption(option_96b989b6f0364a908eb58e1b8c78f008);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x21402855bc8>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#1）使用环形图给出2014年全国各省GDP的排名前10的省份\n",
    "from pyecharts.charts import Pie#从pyecharts中导入line类\n",
    "from pyecharts import options as opts#使用 options 配置项\n",
    "\n",
    "df = pd.read_csv(r\"e:/数据可视化/实验/gdp.csv\")\n",
    "\n",
    "df.sort_values(by = '2014y',ascending=False)\n",
    "\n",
    "a = df.sort_values(by = '2014y',ascending=False).head(10)\n",
    "[list(z) for z in zip(a['province'],a['2014y'])]\n",
    "pie = (\n",
    "    Pie()\n",
    "        .add(\n",
    "        \"\",\n",
    "        [list(z) for z in zip(a['province'], a['2014y'])],\n",
    "        center=[\"40%\", \"30%\"],\n",
    "        radius=[80, 60],\n",
    "        label_opts=opts.LabelOpts(formatter=\"{b}: {d}%\")\n",
    "    ))\n",
    "pie.render_notebook()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"f2acf034b97142f3b61a5a0db030213e\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_f2acf034b97142f3b61a5a0db030213e = echarts.init(\n",
       "                    document.getElementById('f2acf034b97142f3b61a5a0db030213e'), 'white', {renderer: 'canvas'});\n",
       "                var option_f2acf034b97142f3b61a5a0db030213e = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"pie\",\n",
       "            \"name\": \"\\u5e7f\\u4e1c\",\n",
       "            \"clockwise\": true,\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"2016y\",\n",
       "                    \"value\": 80854.91\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"2015y\",\n",
       "                    \"value\": 72812.55\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"2014y\",\n",
       "                    \"value\": 67809.85\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"2013y\",\n",
       "                    \"value\": 62474.79\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"2012y\",\n",
       "                    \"value\": 57067.92\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"2011y\",\n",
       "                    \"value\": 53210.28\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"2010y\",\n",
       "                    \"value\": 46013.06\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"2009y\",\n",
       "                    \"value\": 39482.56\n",
       "                }\n",
       "            ],\n",
       "            \"radius\": [\n",
       "                0,\n",
       "                100\n",
       "            ],\n",
       "            \"center\": [\n",
       "                \"20%\",\n",
       "                \"40%\"\n",
       "            ],\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8,\n",
       "                \"formatter\": \"{b}: {c}\"\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"pie\",\n",
       "            \"name\": \"\\u6c5f\\u82cf\",\n",
       "            \"clockwise\": true,\n",
       "            \"data\": [\n",
       "                {\n",
       "                    \"name\": \"2016y\",\n",
       "                    \"value\": 77388.28\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"2015y\",\n",
       "                    \"value\": 70116.38\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"2014y\",\n",
       "                    \"value\": 65088.32\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"2013y\",\n",
       "                    \"value\": 59753.37\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"2012y\",\n",
       "                    \"value\": 54058.22\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"2011y\",\n",
       "                    \"value\": 49110.27\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"2010y\",\n",
       "                    \"value\": 41425.48\n",
       "                },\n",
       "                {\n",
       "                    \"name\": \"2009y\",\n",
       "                    \"value\": 34457.3\n",
       "                }\n",
       "            ],\n",
       "            \"radius\": [\n",
       "                0,\n",
       "                100\n",
       "            ],\n",
       "            \"center\": [\n",
       "                \"60%\",\n",
       "                \"50%\"\n",
       "            ],\n",
       "            \"roseType\": \"area\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8,\n",
       "                \"formatter\": \"{b}: {c}\"\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"2016y\",\n",
       "                \"2015y\",\n",
       "                \"2014y\",\n",
       "                \"2013y\",\n",
       "                \"2012y\",\n",
       "                \"2011y\",\n",
       "                \"2010y\",\n",
       "                \"2009y\"\n",
       "            ],\n",
       "            \"selected\": {},\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"Pie-\\u73ab\\u7470\\u56fe\\u793a\\u4f8b\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_f2acf034b97142f3b61a5a0db030213e.setOption(option_f2acf034b97142f3b61a5a0db030213e);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x214028439c8>"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#2）取江苏、广东 两省 最近8年数据，用玫瑰图的area类型做出一个逐年环绕的效果\n",
    "from pyecharts.charts import Pie#从pyecharts中导入line类\n",
    "from pyecharts import options as opts#使用 options 配置项\n",
    "\n",
    "df = pd.read_csv(r\"e:/数据可视化/实验/gdp.csv\")\n",
    "\n",
    "years = df.iloc[0,1:9].index.tolist()\n",
    "gd = df.iloc[18,1:9].values.tolist()\n",
    "js = df.iloc[9,1:9].values.tolist()\n",
    "\n",
    "def pie_rosetype() -> Pie:\n",
    "    v = [\"aa\",\"bb\",\"dd\",\"qq\",\"rrr\"]\n",
    "    vv = [10,40,20,15,25]\n",
    "    c = (\n",
    "        Pie()\n",
    "        .add(\n",
    "            \"广东\",\n",
    "            [list(z) for z in zip(years, gd)],\n",
    "            radius=[0, 100],\n",
    "            center=[\"20%\", \"40%\"],\n",
    "            label_opts=opts.LabelOpts(is_show=False),\n",
    "        ) \n",
    "        .add(\n",
    "            \"江苏\",\n",
    "            [list(z) for z in zip(years, js)],\n",
    "            radius=[0, 100],\n",
    "            center=[\"60%\", \"50%\"],\n",
    "            rosetype=\"area\",\n",
    "        )\n",
    "       \n",
    "         .set_series_opts(label_opts=opts.LabelOpts(formatter=\"{b}: {c}\"))\n",
    "        .set_global_opts(title_opts=opts.TitleOpts(title=\"Pie-玫瑰图示例\"))\n",
    "    )\n",
    "    return c\n",
    "pie_rosetype().render_notebook()\n",
    "\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"75374ab48cc84e85a8b778ac6c6cdd87\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_75374ab48cc84e85a8b778ac6c6cdd87 = echarts.init(\n",
       "                    document.getElementById('75374ab48cc84e85a8b778ac6c6cdd87'), 'white', {renderer: 'canvas'});\n",
       "                var option_75374ab48cc84e85a8b778ac6c6cdd87 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"2014y\",\n",
       "            \"data\": [\n",
       "                920.83,\n",
       "                2303.32,\n",
       "                2752.1,\n",
       "                3500.72,\n",
       "                6836.82,\n",
       "                9266.39,\n",
       "                9273.46,\n",
       "                12761.49,\n",
       "                12814.59,\n",
       "                13803.14,\n",
       "                14262.6,\n",
       "                15039.38,\n",
       "                15672.89,\n",
       "                15714.63,\n",
       "                15726.93,\n",
       "                17689.94,\n",
       "                17770.19,\n",
       "                20848.75,\n",
       "                21330.83,\n",
       "                23567.7,\n",
       "                24055.76,\n",
       "                27037.32,\n",
       "                27379.22,\n",
       "                28536.66,\n",
       "                28626.58,\n",
       "                29421.15,\n",
       "                34938.24,\n",
       "                40173.03,\n",
       "                59426.59,\n",
       "                65088.32,\n",
       "                67809.85\n",
       "            ],\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"2014y\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"2014y\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"\\u897f\\u85cf\",\n",
       "                \"\\u9752\\u6d77\\u7701\",\n",
       "                \"\\u5b81\\u590f\",\n",
       "                \"\\u6d77\\u5357\\u7701\",\n",
       "                \"\\u7518\\u8083\\u7701\",\n",
       "                \"\\u8d35\\u5dde\\u7701\",\n",
       "                \"\\u65b0\\u7586\",\n",
       "                \"\\u5c71\\u897f\\u7701\",\n",
       "                \"\\u4e91\\u5357\\u7701\",\n",
       "                \"\\u5409\\u6797\\u7701\",\n",
       "                \"\\u91cd\\u5e86\\u5e02\",\n",
       "                \"\\u9ed1\\u9f99\\u6c5f\\u7701\",\n",
       "                \"\\u5e7f\\u897f\",\n",
       "                \"\\u6c5f\\u897f\\u7701\",\n",
       "                \"\\u5929\\u6d25\\u5e02\",\n",
       "                \"\\u9655\\u897f\\u7701\",\n",
       "                \"\\u5185\\u8499\\u53e4\",\n",
       "                \"\\u5b89\\u5fbd\\u7701\",\n",
       "                \"\\u5317\\u4eac\\u5e02\",\n",
       "                \"\\u4e0a\\u6d77\\u5e02\",\n",
       "                \"\\u798f\\u5efa\\u7701\",\n",
       "                \"\\u6e56\\u5357\\u7701\",\n",
       "                \"\\u6e56\\u5317\\u7701\",\n",
       "                \"\\u56db\\u5ddd\\u7701\",\n",
       "                \"\\u8fbd\\u5b81\\u7701\",\n",
       "                \"\\u6cb3\\u5317\\u7701\",\n",
       "                \"\\u6cb3\\u5357\\u7701\",\n",
       "                \"\\u6d59\\u6c5f\\u7701\",\n",
       "                \"\\u5c71\\u4e1c\\u7701\",\n",
       "                \"\\u6c5f\\u82cf\\u7701\",\n",
       "                \"\\u5e7f\\u4e1c\\u7701\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ],\n",
       "    \"dataZoom\": {\n",
       "        \"show\": true,\n",
       "        \"type\": \"slider\",\n",
       "        \"realtime\": true,\n",
       "        \"start\": 100,\n",
       "        \"end\": 50,\n",
       "        \"orient\": \"vertical\",\n",
       "        \"zoomLock\": false\n",
       "    }\n",
       "};\n",
       "                chart_75374ab48cc84e85a8b778ac6c6cdd87.setOption(option_75374ab48cc84e85a8b778ac6c6cdd87);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x21402855108>"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#1）使用条形图给出2014年全国各省GDP的排名，提供纵向缩放功能。\n",
    "import random\n",
    "from pyecharts.charts import Bar\n",
    "from pyecharts import options as opts\n",
    "df = pd.read_csv(r\"e:/数据可视化/实验/gdp.csv\")\n",
    "year = '2014y'\n",
    "df_of_year = df[['province', year]].sort_values(by =year, ascending=True)\n",
    "\n",
    "provinces = df_of_year['province'].values.tolist()\n",
    "values = df_of_year[year].values.tolist()\n",
    "\n",
    "bar = (\n",
    "       Bar()\n",
    "       .add_xaxis(eval(repr(provinces)))\n",
    "       .add_yaxis(year, eval(repr(values)))\n",
    "       .reversal_axis()\n",
    "       .set_global_opts( datazoom_opts=opts.DataZoomOpts(orient=\"vertical\",range_start =100, range_end=50,))\n",
    "       )\n",
    "\n",
    "bar.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"21309f45dcae40729a430269cb66c7e0\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_21309f45dcae40729a430269cb66c7e0 = echarts.init(\n",
       "                    document.getElementById('21309f45dcae40729a430269cb66c7e0'), 'white', {renderer: 'canvas'});\n",
       "                var option_21309f45dcae40729a430269cb66c7e0 = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"2013y\",\n",
       "            \"data\": [\n",
       "                19800.81,\n",
       "                21818.15,\n",
       "                59753.37,\n",
       "                62474.79\n",
       "            ],\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"label\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"inside\",\n",
       "                    \"color\": \"#fff\",\n",
       "                    \"margin\": 8\n",
       "                },\n",
       "                \"data\": [\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5927\\u503c\",\n",
       "                        \"type\": \"max\"\n",
       "                    },\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5c0f\\u503c\",\n",
       "                        \"type\": \"min\"\n",
       "                    }\n",
       "                ]\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"2012y\",\n",
       "            \"data\": [\n",
       "                17879.4,\n",
       "                20181.72,\n",
       "                54058.22,\n",
       "                57067.92\n",
       "            ],\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"label\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"inside\",\n",
       "                    \"color\": \"#fff\",\n",
       "                    \"margin\": 8\n",
       "                },\n",
       "                \"data\": [\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5927\\u503c\",\n",
       "                        \"type\": \"max\"\n",
       "                    },\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5c0f\\u503c\",\n",
       "                        \"type\": \"min\"\n",
       "                    }\n",
       "                ]\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"2011y\",\n",
       "            \"data\": [\n",
       "                16251.93,\n",
       "                19195.69,\n",
       "                49110.27,\n",
       "                53210.28\n",
       "            ],\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"label\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"inside\",\n",
       "                    \"color\": \"#fff\",\n",
       "                    \"margin\": 8\n",
       "                },\n",
       "                \"data\": [\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5927\\u503c\",\n",
       "                        \"type\": \"max\"\n",
       "                    },\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5c0f\\u503c\",\n",
       "                        \"type\": \"min\"\n",
       "                    }\n",
       "                ]\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"2010y\",\n",
       "            \"data\": [\n",
       "                14113.58,\n",
       "                17165.98,\n",
       "                41425.48,\n",
       "                46013.06\n",
       "            ],\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"label\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"inside\",\n",
       "                    \"color\": \"#fff\",\n",
       "                    \"margin\": 8\n",
       "                },\n",
       "                \"data\": [\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5927\\u503c\",\n",
       "                        \"type\": \"max\"\n",
       "                    },\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5c0f\\u503c\",\n",
       "                        \"type\": \"min\"\n",
       "                    }\n",
       "                ]\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"2013y\",\n",
       "                \"2012y\",\n",
       "                \"2011y\",\n",
       "                \"2010y\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"2013y\": true,\n",
       "                \"2012y\": true,\n",
       "                \"2011y\": true,\n",
       "                \"2010y\": true\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"\\u5317\\u4eac\\u5e02\",\n",
       "                \"\\u4e0a\\u6d77\\u5e02\",\n",
       "                \"\\u6c5f\\u82cf\\u7701\",\n",
       "                \"\\u5e7f\\u4e1c\\u7701\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_21309f45dcae40729a430269cb66c7e0.setOption(option_21309f45dcae40729a430269cb66c7e0);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x2140285cbc8>"
      ]
     },
     "execution_count": 12,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#2）取北京、上海、江苏、广东 四省 2010~2013 四年数据，作不同年对比各省、不同省对比各年的两种形式柱状图，加入markpoint等信息\n",
    "from pyecharts.charts import Bar #从pyecharts中导入line类\n",
    "from pyecharts import options as opts#使用 options 配置项\n",
    "from pyecharts.globals import CurrentConfig\n",
    "import pandas as pd\n",
    "\n",
    "df = pd.read_csv(r\"e:/数据可视化/实验/gdp.csv\")\n",
    "\n",
    "df = df.iloc[[0,8,9,18], [0,4,5,6,7]].set_index(\"province\")\n",
    "\n",
    "\n",
    "def show_bar(df):\n",
    "    bar = (Bar()\n",
    "        .add_xaxis( df.index.tolist())\n",
    "    )   \n",
    "    for col in df.columns:\n",
    "        bar.add_yaxis(col, eval(repr(df[col].values.tolist())))\n",
    "    bar.set_series_opts(\n",
    "                markpoint_opts=opts.MarkPointOpts(\n",
    "                data=[\n",
    "                    opts.MarkPointItem(type_=\"max\", name=\"最大值\"),\n",
    "                    opts.MarkPointItem(type_=\"min\", name=\"最小值\"),\n",
    "                    ]   )  \n",
    "            \n",
    "        ) \n",
    "    return bar\n",
    "\n",
    "show_bar(df).render_notebook()\n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"03e5691da2e04094a07501f838cb308f\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_03e5691da2e04094a07501f838cb308f = echarts.init(\n",
       "                    document.getElementById('03e5691da2e04094a07501f838cb308f'), 'white', {renderer: 'canvas'});\n",
       "                var option_03e5691da2e04094a07501f838cb308f = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u5317\\u4eac\\u5e02\",\n",
       "            \"data\": [\n",
       "                19800.81,\n",
       "                17879.4,\n",
       "                16251.93,\n",
       "                14113.58\n",
       "            ],\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"label\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"inside\",\n",
       "                    \"color\": \"#fff\",\n",
       "                    \"margin\": 8\n",
       "                },\n",
       "                \"data\": [\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5927\\u503c\",\n",
       "                        \"type\": \"max\"\n",
       "                    },\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5c0f\\u503c\",\n",
       "                        \"type\": \"min\"\n",
       "                    }\n",
       "                ]\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u4e0a\\u6d77\\u5e02\",\n",
       "            \"data\": [\n",
       "                21818.15,\n",
       "                20181.72,\n",
       "                19195.69,\n",
       "                17165.98\n",
       "            ],\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"label\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"inside\",\n",
       "                    \"color\": \"#fff\",\n",
       "                    \"margin\": 8\n",
       "                },\n",
       "                \"data\": [\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5927\\u503c\",\n",
       "                        \"type\": \"max\"\n",
       "                    },\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5c0f\\u503c\",\n",
       "                        \"type\": \"min\"\n",
       "                    }\n",
       "                ]\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u6c5f\\u82cf\\u7701\",\n",
       "            \"data\": [\n",
       "                59753.37,\n",
       "                54058.22,\n",
       "                49110.27,\n",
       "                41425.48\n",
       "            ],\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"label\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"inside\",\n",
       "                    \"color\": \"#fff\",\n",
       "                    \"margin\": 8\n",
       "                },\n",
       "                \"data\": [\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5927\\u503c\",\n",
       "                        \"type\": \"max\"\n",
       "                    },\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5c0f\\u503c\",\n",
       "                        \"type\": \"min\"\n",
       "                    }\n",
       "                ]\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u5e7f\\u4e1c\\u7701\",\n",
       "            \"data\": [\n",
       "                62474.79,\n",
       "                57067.92,\n",
       "                53210.28,\n",
       "                46013.06\n",
       "            ],\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"label\": {\n",
       "                \"show\": true,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"markPoint\": {\n",
       "                \"label\": {\n",
       "                    \"show\": true,\n",
       "                    \"position\": \"inside\",\n",
       "                    \"color\": \"#fff\",\n",
       "                    \"margin\": 8\n",
       "                },\n",
       "                \"data\": [\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5927\\u503c\",\n",
       "                        \"type\": \"max\"\n",
       "                    },\n",
       "                    {\n",
       "                        \"name\": \"\\u6700\\u5c0f\\u503c\",\n",
       "                        \"type\": \"min\"\n",
       "                    }\n",
       "                ]\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u5317\\u4eac\\u5e02\",\n",
       "                \"\\u4e0a\\u6d77\\u5e02\",\n",
       "                \"\\u6c5f\\u82cf\\u7701\",\n",
       "                \"\\u5e7f\\u4e1c\\u7701\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u5317\\u4eac\\u5e02\": true,\n",
       "                \"\\u4e0a\\u6d77\\u5e02\": true,\n",
       "                \"\\u6c5f\\u82cf\\u7701\": true,\n",
       "                \"\\u5e7f\\u4e1c\\u7701\": true\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"2013y\",\n",
       "                \"2012y\",\n",
       "                \"2011y\",\n",
       "                \"2010y\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_03e5691da2e04094a07501f838cb308f.setOption(option_03e5691da2e04094a07501f838cb308f);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x21402827b08>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#2）取北京、上海、江苏、广东 四省 2010~2013 四年数据，作不同年对比各省、不同省对比各年的两种形式柱状图，加入markpoint等信息\n",
    "from pyecharts.charts import Bar #从pyecharts中导入line类\n",
    "from pyecharts import options as opts#使用 options 配置项\n",
    "from pyecharts.globals import CurrentConfig\n",
    "import pandas as pd\n",
    "\n",
    "\n",
    "df = pd.read_csv(r\"e:/数据可视化/实验/gdp.csv\")\n",
    "\n",
    "df = df.iloc[[0,8,9,18], [0,4,5,6,7]].set_index(\"province\")\n",
    "\n",
    "\n",
    "def show_bar(df):\n",
    "    bar = (Bar()\n",
    "        .add_xaxis( df.index.tolist())\n",
    "    )   \n",
    "    for col in df.columns:\n",
    "        bar.add_yaxis(col, eval(repr(df[col].values.tolist())))\n",
    "    bar.set_series_opts(\n",
    "                markpoint_opts=opts.MarkPointOpts(\n",
    "                data=[\n",
    "                    opts.MarkPointItem(type_=\"max\", name=\"最大值\"),\n",
    "                    opts.MarkPointItem(type_=\"min\", name=\"最小值\"),\n",
    "                    ]   )  \n",
    "            \n",
    "        ) \n",
    "    return bar\n",
    "\n",
    "show_bar(df.T).render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/html": [
       "\n",
       "<script>\n",
       "    require.config({\n",
       "        paths: {\n",
       "            'echarts':'https://assets.pyecharts.org/assets/echarts.min'\n",
       "        }\n",
       "    });\n",
       "</script>\n",
       "\n",
       "        <div id=\"fbe558afeabd4daf8dfe3b3b49f189ee\" style=\"width:900px; height:500px;\"></div>\n",
       "\n",
       "<script>\n",
       "        require(['echarts'], function(echarts) {\n",
       "                var chart_fbe558afeabd4daf8dfe3b3b49f189ee = echarts.init(\n",
       "                    document.getElementById('fbe558afeabd4daf8dfe3b3b49f189ee'), 'white', {renderer: 'canvas'});\n",
       "                var option_fbe558afeabd4daf8dfe3b3b49f189ee = {\n",
       "    \"animation\": true,\n",
       "    \"animationThreshold\": 2000,\n",
       "    \"animationDuration\": 1000,\n",
       "    \"animationEasing\": \"cubicOut\",\n",
       "    \"animationDelay\": 0,\n",
       "    \"animationDurationUpdate\": 300,\n",
       "    \"animationEasingUpdate\": \"cubicOut\",\n",
       "    \"animationDelayUpdate\": 0,\n",
       "    \"color\": [\n",
       "        \"#c23531\",\n",
       "        \"#2f4554\",\n",
       "        \"#61a0a8\",\n",
       "        \"#d48265\",\n",
       "        \"#749f83\",\n",
       "        \"#ca8622\",\n",
       "        \"#bda29a\",\n",
       "        \"#6e7074\",\n",
       "        \"#546570\",\n",
       "        \"#c4ccd3\",\n",
       "        \"#f05b72\",\n",
       "        \"#ef5b9c\",\n",
       "        \"#f47920\",\n",
       "        \"#905a3d\",\n",
       "        \"#fab27b\",\n",
       "        \"#2a5caa\",\n",
       "        \"#444693\",\n",
       "        \"#726930\",\n",
       "        \"#b2d235\",\n",
       "        \"#6d8346\",\n",
       "        \"#ac6767\",\n",
       "        \"#1d953f\",\n",
       "        \"#6950a1\",\n",
       "        \"#918597\"\n",
       "    ],\n",
       "    \"series\": [\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u7b2c\\u4e00\\u4ea7\\u4e1a\",\n",
       "            \"data\": [\n",
       "                33.38343039639301,\n",
       "                33.17122253899044,\n",
       "                32.13096559378468,\n",
       "                28.438331854480925,\n",
       "                27.14355231143552,\n",
       "                26.80985156314786,\n",
       "                25.693013361696472,\n",
       "                25.10593220338983,\n",
       "                27.115920291407758,\n",
       "                24.525962995271108,\n",
       "                21.791776547932994\n",
       "            ],\n",
       "            \"stack\": \"stack1\",\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u7b2c\\u4e8c\\u4ea7\\u4e1a\",\n",
       "            \"data\": [\n",
       "                44.767987976704866,\n",
       "                44.37363743082341,\n",
       "                43.09100998890122,\n",
       "                42.890417036379766,\n",
       "                43.72749391727494,\n",
       "                43.55253337756032,\n",
       "                43.78780828292229,\n",
       "                42.8319209039548,\n",
       "                41.33811870580673,\n",
       "                41.788714935035124,\n",
       "                43.45726702076292\n",
       "            ],\n",
       "            \"stack\": \"stack1\",\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        },\n",
       "        {\n",
       "            \"type\": \"bar\",\n",
       "            \"name\": \"\\u7b2c\\u4e09\\u4ea7\\u4e1a\",\n",
       "            \"data\": [\n",
       "                21.84858162690212,\n",
       "                22.438369948012745,\n",
       "                24.778024417314096,\n",
       "                28.671251109139305,\n",
       "                29.13868613138686,\n",
       "                29.637615059291818,\n",
       "                30.512530745197104,\n",
       "                32.06214689265537,\n",
       "                31.540604242554103,\n",
       "                33.68532206969377,\n",
       "                34.754670727630646\n",
       "            ],\n",
       "            \"stack\": \"stack1\",\n",
       "            \"barCategoryGap\": \"20%\",\n",
       "            \"label\": {\n",
       "                \"show\": false,\n",
       "                \"position\": \"top\",\n",
       "                \"margin\": 8\n",
       "            },\n",
       "            \"rippleEffect\": {\n",
       "                \"show\": true,\n",
       "                \"brushType\": \"stroke\",\n",
       "                \"scale\": 2.5,\n",
       "                \"period\": 4\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"legend\": [\n",
       "        {\n",
       "            \"data\": [\n",
       "                \"\\u7b2c\\u4e00\\u4ea7\\u4e1a\",\n",
       "                \"\\u7b2c\\u4e8c\\u4ea7\\u4e1a\",\n",
       "                \"\\u7b2c\\u4e09\\u4ea7\\u4e1a\"\n",
       "            ],\n",
       "            \"selected\": {\n",
       "                \"\\u7b2c\\u4e00\\u4ea7\\u4e1a\": true,\n",
       "                \"\\u7b2c\\u4e8c\\u4ea7\\u4e1a\": true,\n",
       "                \"\\u7b2c\\u4e09\\u4ea7\\u4e1a\": true\n",
       "            },\n",
       "            \"show\": true,\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10,\n",
       "            \"itemWidth\": 25,\n",
       "            \"itemHeight\": 14\n",
       "        }\n",
       "    ],\n",
       "    \"tooltip\": {\n",
       "        \"show\": true,\n",
       "        \"trigger\": \"item\",\n",
       "        \"triggerOn\": \"mousemove|click\",\n",
       "        \"axisPointer\": {\n",
       "            \"type\": \"line\"\n",
       "        },\n",
       "        \"textStyle\": {\n",
       "            \"fontSize\": 14\n",
       "        },\n",
       "        \"borderWidth\": 0\n",
       "    },\n",
       "    \"xAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            },\n",
       "            \"data\": [\n",
       "                \"1982\",\n",
       "                \"1983\",\n",
       "                \"1984\",\n",
       "                \"1985\",\n",
       "                \"1986\",\n",
       "                \"1987\",\n",
       "                \"1988\",\n",
       "                \"1989\",\n",
       "                \"1990\",\n",
       "                \"1991\",\n",
       "                \"1992\"\n",
       "            ]\n",
       "        }\n",
       "    ],\n",
       "    \"yAxis\": [\n",
       "        {\n",
       "            \"show\": true,\n",
       "            \"scale\": false,\n",
       "            \"nameLocation\": \"end\",\n",
       "            \"nameGap\": 15,\n",
       "            \"gridIndex\": 0,\n",
       "            \"inverse\": false,\n",
       "            \"offset\": 0,\n",
       "            \"splitNumber\": 5,\n",
       "            \"minInterval\": 0,\n",
       "            \"splitLine\": {\n",
       "                \"show\": false,\n",
       "                \"lineStyle\": {\n",
       "                    \"show\": true,\n",
       "                    \"width\": 1,\n",
       "                    \"opacity\": 1,\n",
       "                    \"curveness\": 0,\n",
       "                    \"type\": \"solid\"\n",
       "                }\n",
       "            }\n",
       "        }\n",
       "    ],\n",
       "    \"title\": [\n",
       "        {\n",
       "            \"text\": \"\\u6211\\u7684\\u7b2c\\u4e00\\u4e2a\\u56fe\\u8868\",\n",
       "            \"subtext\": \"\\u8fd9\\u91cc\\u662f\\u526f\\u6807\\u9898\",\n",
       "            \"padding\": 5,\n",
       "            \"itemGap\": 10\n",
       "        }\n",
       "    ]\n",
       "};\n",
       "                chart_fbe558afeabd4daf8dfe3b3b49f189ee.setOption(option_fbe558afeabd4daf8dfe3b3b49f189ee);\n",
       "        });\n",
       "    </script>\n"
      ],
      "text/plain": [
       "<pyecharts.render.display.HTML at 0x2140296a7c8>"
      ]
     },
     "execution_count": 16,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "#读取数据文件gdp.txt，每行一年数据，字段分别为： 年、总值、第一产值、第二产值、第三产值。完成占比的变化效果图。 其中第三产业在下，第一产业在上。纵坐标为100%\n",
    "from pyecharts.charts import Bar\n",
    "from pyecharts import options as opts\n",
    "\n",
    "with open(r\"e:/数据可视化/实验/gdp.txt\") as f:\n",
    "    info = [line.split('\\t',5) for line in f]\n",
    "    info = [(x[0], *list(map(int, x[1:-1]))) for x in info]\n",
    "    attr = [x[0] for x in info]\n",
    "\n",
    "\n",
    "\n",
    "bar = (\n",
    "    Bar()\n",
    "    .add_xaxis(attr)\n",
    "    .add_yaxis(\"第一产业\", [x[2]/x[1] * 100 for x in info],stack=\"stack1\")\n",
    "    .add_yaxis(\"第二产业\", [x[3]/x[1] * 100 for x in info],stack=\"stack1\")\n",
    "    .add_yaxis(\"第三产业\", [x[4]/x[1] * 100 for x in info],stack=\"stack1\")\n",
    "    .set_global_opts(title_opts=opts.TitleOpts(title=\"我的第一个图表\", subtitle=\"这里是副标题\"))\n",
    "    .set_series_opts(label_opts=opts.LabelOpts(False))\n",
    ")\n",
    "bar.render_notebook()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.7.6"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 4
}
